﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using SavoryBL;

namespace WebApplication
{
    public partial class Post_Product_Projects : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btn_Load.Attributes.Add("OnClick", "return ValidatePostCompnayProduct('" + txtlotarea.ClientID + "','" + txtPriceM2.ClientID + "', '" + txtYear.ClientID + "', '" + up1.ClientID + "', '" + ddlCountry.ClientID + "','" + ddlCity.ClientID + "','" + hdnAlertCounter.ClientID + "');");

                CountryService service = new CountryService();
                List<string> country = service.GetCountry();
                ddlCountry.DataSource = country;
                ddlCountry.DataBind();
                ddlCountry.Items.Insert(0, "Country");
            }
     
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='default.aspx'>Home</a> > <a href='Menu.aspx'>Menu</a> > <span>Post Company Products / Projects</span>";
        }
        public void err(string mess)
        {

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(@"<script language='javascript'>");
            sb.Append(@"alert('" + mess + "');");
            sb.Append(@"</script>");
            if (!ClientScript.IsStartupScriptRegistered("jsscript"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "jsscript", sb.ToString());
            }
        }
        SavoryBL.SavoryUserDetails obj = new SavoryBL.SavoryUserDetails();
        protected void btn_Load_Click(object sender, EventArgs e)
        {
            if (chkNewsLatter.Checked == true)
            {
                ResponseStatus status = ResponseStatus.Failure;
              status = obj.InsertCompanyProductPosted(ddlCountry.SelectedValue, ddlCity.SelectedValue, txtlotarea.Text, txtYear.Text, txtDescription.Text, up1.FileName, up2.FileName, up3.FileName, up4.FileName, up5.FileName, Convert.ToInt32(Session["ID"]));
                if (status==ResponseStatus.Success)
                {
                    string result = System.DateTime.Now.ToString("MM-dd-yyyy");
                    Directory.CreateDirectory(Server.MapPath("UploadedFiles/PostedCompanyProduct/" + result));
                    if (up1.HasFile)
                    {
                        up1.PostedFile.SaveAs(Server.MapPath("UploadedFiles/PostedCompanyProduct/" + result + "/") + up1.FileName);
                    }
                    if (up2.HasFile)
                    {
                        up2.PostedFile.SaveAs(Server.MapPath("UploadedFiles/PostedCompanyProduct/" + result + "/") + up2.FileName);
                    }
                   
                    if (up3.HasFile)
                    {
                        up3.PostedFile.SaveAs(Server.MapPath("UploadedFiles/PostedCompanyProduct/" + result + "/") + up3.FileName);

                    }
                    if (up4.HasFile)
                    {
                        up4.PostedFile.SaveAs(Server.MapPath("UploadedFiles/PostedCompanyProduct/" + result + "/") + up4.FileName);
                    }
                    if (up5.HasFile)
                    {
                        up5.PostedFile.SaveAs(Server.MapPath("UploadedFiles/PostedCompanyProduct/" + result + "/") + up5.FileName);
                    }
                    Response.Redirect("Thanks.aspx");
                }
            }
            else
            {
                err("Please Confirm Above Information");
            }
        }
    }
}